<template>
  <!-- 转派 -->
  <el-dialog
    v-el-drag-dialog
    title="转派"
    :visible.sync="visible"
    width="40%"
    append-to-body
    @close="reset"
  >
    <el-form ref="dataForm" :rules="rules" :model="temp" label-position="right" label-width="80px">
      <el-form-item label="转派给:" prop="userId">
        <el-select v-model="temp.userId" style="width: 100%;" placeholder="请选择">
          <el-option
            v-for="item in personList"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="reset">
        取消
      </el-button>
      <el-button type="primary" @click="success">
        确定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { gasCheckPlanClientMember, gasCheckPlanClientAssignOperator } from '@/api'
  export default {
    name: 'redeploy',
    components: {
    },
    data() {
      return {
        visible: false,
        planCode: '',
        csmAddressIds: '',
        temp: {
          userId: ''
        },
        personList: [],
        rules: {
          userId: [{ required: true, message: '请选择转派人', trigger: 'change' }]
        }
      }
    },
    methods: {
      async open(temp) {
        const { planCode, csmAddressIds } = temp
        this.planCode = planCode
        this.csmAddressIds = csmAddressIds
        await Promise.all([this.personLsit()])
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
        })
      },
      // 安检人
      async personLsit() {
        const res = await gasCheckPlanClientMember({
          orgSNNo: ''
        })
        this.personList = res.data
      },
      success() {
        this.$refs.dataForm.validate(async(valid) => {
          if (!valid) return
          const { status } = await gasCheckPlanClientAssignOperator({
            planCode: this.planCode,
            csmAddressIds: this.csmAddressIds,
            targetUserId: this.temp.userId
          })
          if (status === 200) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.$emit('redUpDataTable')
            this.visible = false
          }
        })
      },
      reset() {
        this.visible = false
        this.planCode = ''
        this.csmAddressIds = ''
        this.temp = {}
        this.personList = []
        this.$refs.dataForm && this.$refs.dataForm.resetFields()
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
